package com.dawnling.amapinfowindows;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;

public class InfoWinAdapter implements AMap.InfoWindowAdapter, View.OnClickListener {
    private ImageView badge;
    private TextView tvTitle;
    private String title;
    private String snippet;
    private TextView tvSnippet;
    private LatLng latLng;
    private Context context;

    public InfoWinAdapter(Context context){
        this.context = context;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        initData(marker);
        View view = LayoutInflater.from(context).inflate(R.layout.custom_info_window, null);
        badge = view.findViewById(R.id.badge);
        tvTitle = view.findViewById(R.id.title);
        tvSnippet = view.findViewById(R.id.snippet);

        tvTitle.setText(title);
        tvSnippet.setText(snippet);
        badge.setOnClickListener(this);
        return view;
    }
    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    private void initData(Marker marker) {
        snippet = marker.getSnippet();
        title = marker.getTitle();
        latLng = marker.getPosition();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.badge:  //点击导航
                OpenGaoDeMap.openGaoDeMap(context, title, latLng.latitude+"", latLng.longitude+"");
                break;
        }
    }
}
